<?php

function type1_url($u, $ex=false, $type1=true) {

	$out = '';
	
	if (isset($u['scheme']))
		$out .= $u['scheme'].".//";
	
	if (isset($u['host']))
		$out .= $u['host'].'/';
	
	if (isset($u['port']))
		$out .= ':'.$u['port'].'/';
	
	if (isset($u['path'])) {
	
		$p = strrpos($u['path'],'/');
		//echo $p.$u['path']."<br>";
		
		if ( $p !== false ) {
		
			$file = substr($u['path'],$p+1);
			
			$first = substr($u['path'],0, $p);
			
			//echo $file."<br>";
			
			if (substr($first,0,1) == '/')
				$first = substr($first,1);
			
			$out .= $first . '/';
			
			$p2 = strpos($file,'.');
			
			if ( $p2 !== false ) {
			
				$file_outext = substr($file, 0, $p2);
				
				$out .= $file_outext;
				
				$out .= ($type1?'-':'/');
			}
		} else {
			$out .= $u['path'];
		}
	}
	
	if (isset($u['query'])) {
				
		$form1 = explode('&', $u['query']);
		
		foreach($form1 as $v ) {
		
			$frmdata = explode('=', $v);
			
			if ($ex)
				$out .= $frmdata[0] . ($type1?'-':'/') . $frmdata[1].($type1?'-':'/');
			else
				$out .= $frmdata[0] . ($type1?'-':'/') . '(Any Value)'. ($type1?'-':'/');
		}
		
		if ($type1)
			$out = substr($out,0, -1);
	}
	
	if (isset($u['fragment']))
		$out .= '#'.$u['fragment'];
		
	echo $out;
	
}

function type_htaccess($page, $flag=false, $sec=false) {

	$out = 'RewriteRule ';
	
	$p = strrpos($page,'/');
	
	$url = substr($page, $p+1);
	
	$temp = explode('?',$url);
	
	$p2 = strpos($temp[0],'.');
	
	if ( $p2 !== false ) {
	
		$file_outext = substr($temp[0],0, $p2);
		if ($flag)
			$out .= $file_outext.'/';
		else
			$out .= $file_outext.'-';
	}
	
	$form1 = explode('&', $temp[1]);
	$form2 = '';
	$i = 1;
	
	foreach($form1 as $v ) {
	
		$frmdata = explode('=', $v);
		
		if ($flag) {
			$out .= $frmdata[0] . '/' . '(.*)/';
		} else {
			$out .= $frmdata[0] . '-' . '(.*)-';
		}

		$form2 .= $frmdata[0] . '=' . '$' . $i++ . '&';
	}
	$form2 = substr($form2,0, -1);

	if (!$sec)
		$out = substr($out,0, -1);

	if ($flag)
		$out .= ' ';
	else
		$out .= '\.htm$ ';

	$out .= $temp[0] . '?' . $form2;
	
	return $out;
}
?>